local hx__tianjian = fk.CreateSkill {

  name = "hx__tianjian",

  tags = { Skill.Compulsory, },

}

local hx_jianshen__getjianqi = function (room, player, num)
  local maxnum
  if player:usedSkillTimes("hx__tuiying",Player.HistoryGame) == 0 then
    maxnum = 3 - player:getMark("@hx__jianqi")
  else
    maxnum = 5 - player:getMark("@hx__jianqi")
  end
   local getnum = math.min(maxnum,num)
   room:addPlayerMark(player,"@hx__jianqi",getnum)
end


hx__tianjian:addEffect(fk.TurnStart, {
  name = "hx__tianjian",
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(hx__tianjian.name) and target and target == player then
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
      hx_jianshen__getjianqi(room,player,3)
      local use = room:askToUseVirtualCard(player,{ name = "slash", subcards = nil, skill_name = hx__tianjian.name, prompt = "#hx__tianjian__slash", cancelable = true, skip = true, extra_data = {bypass_distances = true,bypass_times =true} })
      if use then
        room:removePlayerMark(player,"@hx__qianqi",1)
        local targets = use.tos
        for _, v in ipairs(targets) do
          room:addTableMark(player,MarkEnum.MarkArmorInvalidTo.."-phase",v.id)
        end
        room:useCard(use)
        room:setPlayerMark(player,MarkEnum.MarkArmorInvalidTo.."-phase",0)
      end
  end,
})

hx__tianjian:addEffect(fk.Damage, {
  name = "hx__tianjian",
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(hx__tianjian.name) and target and target == player then
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
      if data.skillName ~= "hx__wanjian" then
         hx_jianshen__getjianqi(room,player,data.damage)
      end
  end,
})
hx__tianjian:addEffect(fk.Damaged, {
  name = "hx__tianjian",
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(hx__tianjian.name) and target and target == player then
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
      if data.skillName ~= "hx__wanjian" then
         hx_jianshen__getjianqi(room,player,data.damage)
      end
  end,
})

hx__tianjian:addEffect("targetmod", {
  name= "#hx__tianjian__targetmod",
  bypass_distances = function (self, player, skill, card, to)
    return player:hasSkill("hx__tianjian") and card.trueName == "slash"
  end,
  bypass_times = function (self, player, skill, scope, card, to)
    return player:hasSkill("hx__tianjian") and card.trueName == "slash"
  end,
})

return hx__tianjian